package com.situ.user.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import com.situ.user.bean.User;

//拦截器
@Component
public class UserInterceptor implements HandlerInterceptor {

	// 判断用户是否登录
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		if (user != null) {

			return true;
		} else {
			response.sendRedirect("/user/login");
			return false;
		}
	}
}
